﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Org.BouncyCastle.Crypto.Macs;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Utilities.Encoders;
using Smcrypto;

namespace Gfs.Smcrypto
{
    public class SM3Utils
    {
        public string secretKey = "";
        public string 加密(string data)
        {
            byte[] msg1 = Encoding.Default.GetBytes(data);
            byte[] key1 = Encoding.Default.GetBytes(secretKey);

            KeyParameter keyParameter = new KeyParameter(key1);
            SM3Digest sm3 = new SM3Digest();

            //HMac mac = new HMac(sm3);//带密钥的杂凑算法
            //mac.Init(keyParameter);
            sm3.BlockUpdate(msg1, 0, msg1.Length);
            // byte[] result = new byte[sm3.GetMacSize()];
            byte[] result = new byte[sm3.GetDigestSize()];
            sm3.DoFinal(result, 0);
            return Encoding.ASCII.GetString(Hex.Encode(result));
        }
    }
}
